package com.itfreer.arcgis;

import com.esri.arcgisruntime.geometry.Geometry;
import com.esri.arcgisruntime.geometry.GeometryEngine;
import com.esri.arcgisruntime.geometry.GeometryType;
import com.esri.arcgisruntime.geometry.Polygon;
import com.esri.arcgisruntime.geometry.Polyline;

import java.util.List;

/**
 * Geometry 辅助类
 */
public class GeometryUtils
{
    /**
     * 判断要素合并后是否为单一部分要素
     * @param geometries
     * @return
     */
    public static Boolean CheckGeometryUnionIsSample(List<Geometry> geometries)
    {
        if(geometries == null || geometries.size() == 0 || geometries.size() == 1)
            return  false;

        for(Integer i = 0;i<geometries.size();i++)
        {
            if(geometries.get(i) == null || geometries.get(i).isEmpty())
                return  false;
        }

        Geometry geometry = GeometryEngine.union(geometries);
        if(geometry == null || geometry.isEmpty())
            return  false;

        if(geometry.getGeometryType() == GeometryType.POLYGON)
        {
            Polygon polygon = (Polygon) geometry;
            if(polygon.getParts().size()>1)
                return false;

        }
        else if(geometry.getGeometryType() == GeometryType.POLYLINE)
        {
            Polyline polyline = (Polyline) geometry;
            if(polyline.getParts().size()>1)
                return false;
        }

        return  true;
    }
}
